package TestDemo2;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;

      }
}

public class TestDemo {
    public boolean hasCycle(ListNode head) {
        Queue queue=new LinkedList();

        Stack<ListNode> stack=new Stack();
        ListNode cur=head;
        while(!stack.contains(cur)){
            stack.push(cur);
            cur=cur.next;
            if(cur.next==null){
                return false;
            }
        }
        return true;
    }
}
